home *** CD-ROM | disk | FTP | other *** search
/ Kit PC World De Ampliacion De Windows 95 / Kit PC World de ampliacion de Windows 95.iso / internet / sweeper / samples / docobj / idocsite.cpp < prev    next >
C/C++ Source or Header  |  1995-11-21  |  3KB  |  145 lines

  1. /*
  2.  * IDOCSITE.CPP
  3.  * IOleDocumentSite for Document Objects CSite class
  4.  *
  5.  * Copyright (c)1995 Microsoft Corporation, All Rights Reserved
  6.  * Kraig Brockschmidt, kraigb@microsoft.com
  7.  */
  8.  
  9.  
  10. #include "framer.h"
  11.  
  12.  
  13. /*
  14.  * CImpIOleDocumentSite::CImpIOleDocumentSite
  15.  * CImpIOleDocumentSite::~CImpIOleDocumentSite
  16.  *
  17.  * Parameters (Constructor):
  18.  *  pSite           PCSite of the site we're in.
  19.  *  pUnkOuter       LPUNKNOWN to which we delegate.
  20.  */
  21.  
  22. CImpIOleDocumentSite::CImpIOleDocumentSite(PCSite pSite
  23.     , LPUNKNOWN pUnkOuter)
  24.     {
  25.     m_cRef=0;
  26.     m_pSite=pSite;
  27.     m_pUnkOuter=pUnkOuter;
  28.     return;
  29.     }
  30.  
  31. CImpIOleDocumentSite::~CImpIOleDocumentSite(void)
  32.     {
  33.     return;
  34.     }
  35.  
  36.  
  37.  
  38. /*
  39.  * CImpIOleDocumentSite::QueryInterface
  40.  * CImpIOleDocumentSite::AddRef
  41.  * CImpIOleDocumentSite::Release
  42.  *
  43.  * Purpose:
  44.  *  IUnknown members for CImpIOleDocumentSite object.
  45.  */
  46.  
  47. STDMETHODIMP CImpIOleDocumentSite::QueryInterface(REFIID riid
  48.     , void **ppv)
  49.     {
  50.     return m_pUnkOuter->QueryInterface(riid, ppv);
  51.     }
  52.  
  53.  
  54. STDMETHODIMP_(ULONG) CImpIOleDocumentSite::AddRef(void)
  55.     {
  56.     ++m_cRef;
  57.     return m_pUnkOuter->AddRef();
  58.     }
  59.  
  60. STDMETHODIMP_(ULONG) CImpIOleDocumentSite::Release(void)
  61.     {
  62.     --m_cRef;
  63.     return m_pUnkOuter->Release();
  64.     }
  65.  
  66.  
  67.  
  68.  
  69. /*
  70.  * CImpIOleDocumentsite::ActivateMe
  71.  *
  72.  * Purpose:
  73.  *  Instructs the container to activate the object in this site as
  74.  *  a document object.
  75.  *
  76.  * Parameters:
  77.  *  pView           IOleDocumentView * of the object to activate.
  78.  *
  79.  * Return Value:
  80.  *  HRESULT         NOERROR if successful, error code otherwise.
  81.  */
  82.  
  83. STDMETHODIMP CImpIOleDocumentSite::ActivateMe(IOleDocumentView *pView)
  84.     {
  85.     RECT                rc;
  86.     
  87.     /*
  88.      * If we're passed a NULL view pointer, then try to get one from
  89.      * the document object (the object within us).
  90.      */
  91.     if (NULL==pView)
  92.         {
  93.         IOleDocument *pDoc;
  94.  
  95.         if (FAILED(m_pSite->m_pObj->QueryInterface(IID_IOleDocument
  96.             , (void **)&pDoc)))
  97.             return E_FAIL;
  98.  
  99.         if (FAILED(pDoc->CreateView(m_pSite->m_pImpIOleIPSite, NULL
  100.             , 0, &pView)))
  101.             return E_OUTOFMEMORY;
  102.         }
  103.     else
  104.         {
  105.         //Make sure that the view has our client site
  106.         pView->SetInPlaceSite(m_pSite->m_pImpIOleIPSite);
  107.  
  108.         //We're holding onto the pointer, so AddRef it.
  109.         pView->AddRef();
  110.         }
  111.  
  112.  
  113.     /*
  114.      * Activation steps, now that we have a view:
  115.      *
  116.      *  1.  Call IOleDocumentView::SetInPlaceSite (assume done since
  117.      *      either the view already knows, or IOleDocument::CreateView
  118.      *      has done it already.
  119.      *
  120.      *  2.  Call IOleDocumentView::SetRect to give a bunch of space to
  121.      *      the view.  In our case this is the whole client area of
  122.      *      the CPages window.  (Patron doesn't use SetRectComplex)
  123.      *
  124.      *  3.  Call IOleDocumentView::Show to make the thing visible.
  125.      *
  126.      *  4.  Call IOleDocumentView::UIActivate to finish the job.
  127.      *
  128.      */
  129.  
  130.     m_pSite->m_fDocObj==TRUE;
  131.     m_pSite->m_pIOleDocView=pView;
  132.     
  133.     //This sets up toolbars and menus first    
  134.     pView->UIActivate(TRUE);
  135.  
  136.     //Set the window size sensitive to new toolbars
  137.     GetClientRect(m_pSite->m_hWnd, &rc);
  138.     pView->SetRect(&rc);
  139.  
  140.     //Makes it all active
  141.     pView->Show(TRUE);    
  142.  
  143.     return NOERROR;
  144.     }
  145.